package com.example.yuejian21.nongfusanquan.yuejian21.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.jude.rollviewpager.RollPagerView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;

public class TabFragment extends Fragment  {

    //声明变量
    private View view=null;



    private ActivityFragment activityFragment;
    private MatchFragment contestFragment;
    private GiftFragment giftFragment;


    private RadioButton activityRadio;
    private RadioButton giftRadio;
    private RadioButton contestRadio;

    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;

    public TabFragment(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view= inflater.inflate(R.layout.fragment_tab, container, false);



        return view;
    }


    //精选活动，近期比赛，权威大师等fragment
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        activityRadio = (RadioButton) view.findViewById(R.id.jingxuanActivity);
        contestRadio = (RadioButton) view.findViewById(R.id.jinqiContest);
        giftRadio = (RadioButton) view.findViewById(R.id.radio_gift);

        activityRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    activityFragment = new ActivityFragment();
                    replaceFragment(activityFragment);
                }
            }
        });

        contestRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    contestFragment = new MatchFragment();
                    replaceFragment(contestFragment);
                }
            }
        });
        giftRadio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    giftFragment = new GiftFragment();
                    replaceFragment(giftFragment);
                }
            }
        });

        fragmentManager=getChildFragmentManager();
        activityRadio.setChecked(true);

    }
    private void replaceFragment(Fragment fragment){
        transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_container,fragment);
        transaction.commit();
    }



}